* ******** *
* ANALYSIS *
* ******** *

/*

Disclaimer:

Any views expressed are those of the authors and not those of the U.S. Census Bureau. The Census Bureau 
has reviewed this data product to ensure appropriate access, use, and disclosure avoidance protection of
the confidential source data used to produce this product. This research was performed at a Federal 
Statistical Research Data Center under FSRDC Project Number 2896. (CBDRB-FY25-P2896-R11993)


Note to users:

The U.S. Census Bureau prohibits the release of replication data but permits the release of replication
code so long as that code does not contain data, including hardcoded values that rely on restricted
information. We have therefore redacted our code accordingly. Users who have been granted access to 
the data at a Federal Statistical Research Data Center can consult the documentation that accompanies the
datasets to recover the hardcoded values that were redacted below.

*/

* ---------------------------------------------------------------------------- *

* ------------- *
* PRELIMINARIES * 
* ------------- *

* basics
clear
set more off
set seed [redacted]


* log stuff
cap log close
log using "logs/analysis", replace


* directory globals
global decennial "[redacted]"
global data "data/"
global code "code/"
global output "output/[date]/output/"
global disc = "output/[date]/support/"

cd "/projects/"


* disclosure globals
global tempstats "${disc}tempstats.dta"
global spreadsheet "${disc}disclosure_stats.dta"
global id id


* remove old disclosure stat files
cap rm ${disc}disclosure_stats.dta
cap rm ${disc}disclosure_stats.xlsx
cap rm ${output}compliers.csv


* ---------------------------------------------------------------------------- *

* -------------- *
* VARIABLE LISTS *
* -------------- *

* variable lists for descriptives
global desc_indvars draft_risk veteran 

global desc_covars age_immig yrs_since_immig

global desc_depvars naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability engl_ability_pooled spouse_notconatl spouse_native  married college_some college_grad income_total


* variable lists for profile descriptives
global desc_profilevars1 age_immig profileage  

global desc_profilevars2 engl_exclusive profilecanada profileitaly profilegermany

global desc_profilevars3 profilepr profilemexico 

global desc_profilevars3pool profilepr profilemexico profilewhite profileblack profileasian profilehispanic

global desc_profilevars4 profileothers
	
	
* covariate list 
global covars age_immig i.birth_year i.birth_month

global controls age_immig i.bpl i.birth_year i.birth_month


* load data
use "${data}analysis.dta", clear



* ---------------------------------------------------------------------------- *

* ------------------------ *
* DESCRIPTIVES: TABLE A4.1 *
* ------------------------ *	

* set up matrix
cap mata drop DESC
mata: DESC = J(48, 4, "")


* loop over DVs
local row = 1

forvalues n = 1/3 { 
foreach var of varlist draft_risk veteran age_immig yrs_since_immig naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability engl_ability_pooled spouse_notconatl spouse_native married college_some college_grad unemployed {
			
	local serow = `row' + 1
	
	// mean and N
	su `var' if sample_main`n' == 1
	local m : display %5.4f `r(mean)'
	local se : display %5.4f `r(sd)'

	mata: DESC[`row',1] = "`m'"
	mata: DESC[`row',2] = "`se'"
	mata: DESC[`row',3] = "`r(N)'"
	mata: DESC[`row',4] = "sample_main`n'"
	local row = `row' + 1
}
}

mata DESC


* output to latex
mmat2tex DESC using "${output}descriptives.tex", replace ///
	rownames("Draft risk" "Veteran"   "Age at immigration"  "Years since immigration"   "Naturalized"  "Residential integration (tract)"   "Residential integration (blkgrp)"  "English only"   "English ability"   "English ability (pooled)"  "Non-co-national spouse" "Native-born spouse"   "Married"   "Some college"   "College graduate"  "Unemployed" "Draft risk" "Veteran"   "Age at immigration"  "Years since immigration"   "Naturalized"  "Residential integration (tract)"   "Residential integration (blkgrp)"  "English only"   "English ability"   "English ability (pooled)"  "Non-co-national spouse"  "Native-born spouse"   "Married"   "Some college"   "College graduate"  "Unemployed" "Draft risk" "Veteran"   "Age at immigration"  "Years since immigration"   "Naturalized"  "Residential integration (tract)"   "Residential integration (blkgrp)"  "English only"   "English ability"   "English ability (pooled)" "Non-co-national spouse"  "Native-born spouse" "Married"   "Some college"   "College graduate" "Unemployed") ///
	colnames("Mean" "S.D." "Observations" "Sample") ///
	insertendrow(1 "\hline")

	

* ---------------------------------------------------------------------------- *

* --------------------------------------------------- *
* VETERANS X DRAFT RISK: TABLE 1 (FIRST FOUR COLUMNS) *
* --------------------------------------------------- *

* Pooled sample
tab2xl draft_risk veteran if sample_main1 == 1 ///
	using "${output}tabs_pool", row(1) col(1) sheet(1949-1952)
	
forvalues y = 1949/1952 {
	
tab2xl draft_risk veteran if sample_main1 == 1 & birth_year == `y' ///
	using "${output}tabs_pool", row(1) col(1) sheet(`y')
}

* NOTE: "tabs_pool" is used to create the first 4 columns of Table 1 in the main text. "# Draft Eligible" is the total as reported in each cohort's tab. To calculate % at risk of draft, divide the total for which draft risk = 1 by the total number of those who are draft eligible. To calculate % veterans, divide the total for which veteran = 1 by the total number of those who are draft eligible.


* Westerners
tab2xl draft_risk veteran if sample_main2 == 1 ///
	using "${output}tabs_west", row(1) col(1) sheet(1949-1952)

forvalues y = 1949/1952 {

tab2xl draft_risk veteran if sample_main2 == 1 & birth_year == `y' ///
	using "${output}tabs_west", row(1) col(1) sheet(`y')

}
	

* Non-Westerners
tab2xl draft_risk veteran if sample_main3 == 1 ///
	using "${output}tabs_nonwest", row(1) col(1) sheet(1949-1952)

forvalues y = 1949/1952 {
		
tab2xl draft_risk veteran if sample_main3 == 1 & birth_year == `y' ///
	using "${output}tabs_nonwest", row(1) col(1) sheet(`y')

}



* ---------------------------------------------------------------------------- *

* -------------------------------------------------------- *
* FIRST STAGE ANALYSIS: TABLE A6.2 and COLUMN 5 OF TABLE 1 *
* -------------------------------------------------------- *

* Set up
xtset bpl

* First stage (pooled) immigrants
eststo clear
cap estimates drop s1*

eststo: xtivreg2 res_integrate_tract age_immig byear_* bmonth_* (veteran = draft_risk) if sample_main1 == 1, robust fe first savefirst savefprefix(s1)
estadd scalar wid = `e(widstat)': s1veteran

forvalues y = 1948/1953 {

eststo: xtivreg2 res_integrate_tract age_immig bmonth_* (veteran = draft_risk) if birth_year == `y', robust fe first savefirst savefprefix(s1_`y')
estadd scalar wid = `e(widstat)': s1_`y'veteran

}

esttab s1* using "${output}first_pool.csv", replace ///
	stats(wid N, label("WID statistic" "Observations")) ///
	b(a4) se(a4) sfmt(a4) ///
	scalar(wid) ///
	starlevels(* 0.05 ** 0.01 *** 0.001) ///
	drop(bmonth_* byear_* age_immig) ///
	nodepvars label nonotes ///
	addnotes("Standard errors in parentheses. * p<0.05 ** p<0.01 *** p<0.001") ///
	mtitles("1949--1952" "1948" "1949" "1950" "1951" "1952" "1953")
	

* NOTE: "first_pool" is used to create the last "compliers" column in Table 1 of the manuscript. Specifically, the compliance rate for each year is the corresponding coefficient on "draft risk" as reported in "first_pool".	
	
	
* First stage, western-origin immigrants
eststo clear
cap estimates drop s1*

eststo: xtivreg2 res_integrate_tract age_immig byear_* bmonth_* (veteran = draft_risk) if sample_main2 == 1, robust fe first savefirst savefprefix(s1)
estadd scalar wid = `e(widstat)': s1veteran

forvalues y = 1948/1953 {
eststo: xtivreg2 res_integrate_tract age_immig bmonth_* (veteran = draft_risk) if birth_year == `y' & origin == 1, robust fe first savefirst savefprefix(s1_`y')
estadd scalar wid = `e(widstat)': s1_`y'veteran

}

esttab s1* using "${output}first_west.csv", replace ///
	stats(wid N, label("WID statistic" "Observations")) ///
	b(a4) se(a4) sfmt(a4) ///
	starlevels(* 0.05 ** 0.01 *** 0.001) ///
	drop(bmonth_* byear_* age_immig) ///
	nodepvars label nonotes ///
	addnotes("Standard errors in parentheses. * p<0.05 ** p<0.01 *** p<0.001") ///
	mtitles("1949--1952" "1948" "1949" "1950" "1951" "1952" "1953")

	

* First stage, nonwestern-origin immigrants
eststo clear
cap estimates drop s1*

eststo: xtivreg2 res_integrate_tract age_immig byear_* bmonth_* (veteran = draft_risk) if sample_main3 == 1, robust fe first savefirst savefprefix(s1)
estadd scalar wid = `e(widstat)': s1veteran

forvalues y = 1948/1953 {
	
eststo: xtivreg2 res_integrate_tract age_immig bmonth_* (veteran = draft_risk) if birth_year == `y' & origin == 0, robust fe first savefirst savefprefix(s1_`y')
estadd scalar wid = `e(widstat)': s1_`y'veteran

}


esttab s1* using "${output}first_nonwest.csv", replace ///
	stats(wid N, label("WID statistic" "Observations")) ///
	b(a4) se(a4) sfmt(a4) ///
	starlevels(* 0.05 ** 0.01 *** 0.001) ///
	drop(bmonth_* byear_* age_immig) ///
	nodepvars label nonotes ///
	addnotes("Standard errors in parentheses. * p<0.05 ** p<0.01 *** p<0.001") ///
	mtitles("1949--1952" "1948" "1949" "1950" "1951" "1952" "1953")


	
* ---------------------------------------------------------------------------- *
	
* ------------------------- *
* MAIN ANALYSIS: TABLES 2-4 *
* ------------------------- *	

xtset bpl


* All immigrants: Table 2
* -----------------------

* set up matrix
cap mata drop POOL
mata: POOL = J(24, 5, "")


* loop over DVs
local row = 1
foreach var of varlist naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability engl_ability_pooled spouse_notconatl spouse_native married college_some college_grad unemployed {
	
	// set up matrix
	local serow = `row' + 1
		
	
	// mean
	reg `var' if sample_main1 == 1
	local b : display %5.4f _b[_cons]
	mata: POOL[`row',1] = "`b'"
	mata: POOL[`row',5] = "`e(N)'"

	
	// OLS
	xtreg `var' veteran ${covars} if sample_main1 == 1, vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: POOL[`row',2] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: POOL[`row',2] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: POOL[`row',2] = "`b'**"
	}
	if `p' < 0.001 {
		mata: POOL[`row',2] = "`b'***"
	}
	mata: POOL[`serow',2] = "(`se')"

	
	// ITT
	xtreg `var' draft_risk ${covars} if sample_main1 == 1, vce(robust) fe
	local b : display %5.4f _b[draft_risk]
	local se : display %5.4f _se[draft_risk]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: POOL[`row',3] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: POOL[`row',3] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: POOL[`row',3] = "`b'**"
	}
	if `p' < 0.001 {
		mata: POOL[`row',3] = "`b'***"
	}
	mata: POOL[`serow',3] = "(`se')"

	
	// 2SLS
	xtivreg `var' ${covars} (veteran = draft_risk) if sample_main1 == 1, vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: POOL[`row',4] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: POOL[`row',4] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: POOL[`row',4] = "`b'**"
	}
	if `p' < 0.001 {
		mata: POOL[`row',4] = "`b'***"
	}
	mata: POOL[`serow',4] = "(`se')"

	local row = `row' + 2

	
}


* looking at the results
mata POOL


	
* output to latex
mmat2tex POOL using "${output}main_pool.tex", replace ///
	rownames("Naturalized" "" "Residential integration (tract)" "" "Residential integration (block group)" "" "Only English" "" "English ability" "" "English ability (pooled)" "" "Non-co-national spouse" "" "Native-born spouse" "" "Married" "" "Some college" "" "College graduate" "" "Unemployed" "") ///
	colnames("Means" "OLS" "ITT" "2SLS" "Sample Size") ///
	insertendrow(1 "\hline")
	
	

* Western-origin immigrants: Table 3
* ----------------------------------

* set up matrix
cap mata drop WEST
mata: WEST = J(24, 5, "")


* loop over DVs
local row = 1
foreach var of varlist naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability  engl_ability_pooled spouse_notconatl spouse_native married college_some college_grad unemployed {
	
	// set up matrix
	local serow = `row' + 1

		
	// mean
	reg `var' if sample_main2 == 1
	local b : display %5.4f _b[_cons]
	mata: WEST[`row',1] = "`b'"
	mata: WEST[`row',5] = "`e(N)'"
	
	// OLS
	xtreg `var' veteran ${covars} if sample_main2 == 1, vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: WEST[`row',2] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: WEST[`row',2] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: WEST[`row',2] = "`b'**"
	}
	if `p' < 0.001 {
		mata: WEST[`row',2] = "`b'***"
	}
	mata: WEST[`serow',2] = "(`se')"
	
	
	// ITT
	xtreg `var' draft_risk ${covars} if sample_main2 == 1, vce(robust) fe
	local b : display %5.4f _b[draft_risk]
	local se : display %5.4f _se[draft_risk]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: WEST[`row',3] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: WEST[`row',3] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: WEST[`row',3] = "`b'**"
	}
	if `p' < 0.001 {
		mata: WEST[`row',3] = "`b'***"
	}
	mata: WEST[`serow',3] = "(`se')"

	
	// 2SLS
	xtivreg `var' ${covars} (veteran = draft_risk) if sample_main2 == 1, vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: WEST[`row',4] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: WEST[`row',4] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: WEST[`row',4] = "`b'**"
	}
	if `p' < 0.001 {
		mata: WEST[`row',4] = "`b'***"
	}
	mata: WEST[`serow',4] = "(`se')"

	local row = `row' + 2
	
}


* looking at the results
mata WEST


* output to latex
mmat2tex WEST using "${output}main_west.tex", replace ///
	rownames("Naturalized" "" "Residential integration (tract)" "" "Residential integration (block group)" "" "Only English" "" "English ability" "" "English ability (pooled)" "" "Non-co-national spouse" "" "Native-born spouse" "" "Married" "" "Some college" "" "College graduate" "" "Unemployed" "") ///
	colnames("Means" "OLS" "ITT" "2SLS" "Sample Size") ///
	insertendrow(1 "\hline")



* Non-Western-origin immigrants: Table 4
* --------------------------------------

* set up matrix
cap mata drop NONWEST
mata: NONWEST = J(24, 5, "")


* loop over DVs
local row = 1
foreach var of varlist naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability engl_ability_pooled spouse_notconatl spouse_native  married college_some college_grad unemployed {
	
	// set up matrix
	local serow = `row' + 1
	
	
	// mean
	reg `var' if sample_main3 == 1
	local b : display %5.4f  _b[_cons]
	mata: NONWEST[`row',1] = "`b'"
	mata: NONWEST[`row',5] = "`e(N)'"
	
	// OLS
	xtreg `var' veteran ${covars} if sample_main3 == 1, vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]

	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: NONWEST[`row',2] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: NONWEST[`row',2] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: NONWEST[`row',2] = "`b'**"
	}
	if `p' < 0.001 {
		mata: NONWEST[`row',2] = "`b'***"
	}
	mata: NONWEST[`serow',2] = "(`se')"
	
	
	// ITT
	xtreg `var' draft_risk ${covars} if sample_main3 == 1, vce(robust) fe
	local b : display %5.4f _b[draft_risk]
	local se : display %5.4f _se[draft_risk]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: NONWEST[`row',3] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: NONWEST[`row',3] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: NONWEST[`row',3] = "`b'**"
	}
	if `p' < 0.001 {
		mata: NONWEST[`row',3] = "`b'***"
	}
	mata: NONWEST[`serow',3] = "(`se')"

	
	// 2SLS
	xtivreg `var' ${covars} (veteran = draft_risk) if sample_main3 == 1, vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: NONWEST[`row',4] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: NONWEST[`row',4] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: NONWEST[`row',4] = "`b'**"
	}
	if `p' < 0.001 {
		mata: NONWEST[`row',4] = "`b'***"
	}
	mata: NONWEST[`serow',4] = "(`se')"

	local row = `row' + 2
	
	
}


* looking at the results
mata NONWEST


* output to latex
mmat2tex NONWEST using "${output}main_nonwest.tex", replace ///
	rownames("Naturalized" "" "Residential integration (tract)" "" "Residential integration (block group)" "" "Only English" "" "English ability" "" "English ability (pooled)" "" "Non-co-national spouse" "" "Native-born spouse" ""  "Married" "" "Some college" "" "College graduate" "" "Unemployed" "") ///
	colnames("Means" "OLS" "ITT" "2SLS" "Sample Size") ///	
	insertendrow(1 "\hline")




* ---------------------------------------------------------------------------- *

* -------------------------------------------------- *
* COMPLIERS DESCRIPTIVES: FIGURE A7.9 AND TABLE A7.3 *
* -------------------------------------------------- *

* All immigrants: Figure A7.9 and Table A7.3
* ------------------------------------------

* Note: The code below produces the underlying data in Figure A7.9

* Main profile variables
foreach var in $desc_profilevars3pool $desc_profilevars2 origin $desc_profilevars1  {
	
	ivdesc `var' veteran draft_risk if sample_main1 == 1
	matrix M`var' = r(ivdesc)

}


* Proportions of compliers, AT and NT
matrix define P = J(4,2,0)
matrix rownames P = "Whole Sample" "Complier" "Never-taker" "Always-taker"
matrix colnames P = "Proportion" "Boot.-SE"
forvalues r = 1 / 4 {
	matrix P[`r',1] = Mprofileage[`r',3] 
	matrix P[`r',2] = Mprofileage[`r',4] 
}



* View the matrices
matrix list P


* Tables for graphing later
mat2txt, matrix(P) saving("${output}compliers_pool.csv") title("Proportion") format(%5.4f)  append

foreach var in $desc_profilevars1 origin $desc_profilevars2 $desc_profilevars3 {
	mat2txt, matrix(M`var') saving("${output}compliers_pool.csv") title(`var') format(%5.4f) append
}

	
* Western-origin immigrants 
* -------------------------

* Main profile variables
foreach var in $desc_profilevars2 $desc_profilevars1  {
	
	ivdesc `var' veteran draft_risk if sample_main2 == 1
	matrix N`var' = r(ivdesc)

}


* Proportions of compliers, AT and NT
matrix define Q = J(4,2,0)
matrix rownames Q = "Whole Sample" "Complier" "Never-taker" "Always-taker"
matrix colnames Q = "Proportion" "Boot.-SE"
forvalues r = 1 / 4 {
	matrix Q[`r',1] = Nprofileage[`r',3] 
	matrix Q[`r',2] = Nprofileage[`r',4] 
}


* View the matrices
matrix list Q


* Tables for graphing later

mat2txt, matrix(Q) saving("${output}compliers_west.csv") title("Proportion") format(%5.4f)  append

foreach var in $desc_profilevars1  $desc_profilevars2  {
	mat2txt, matrix(N`var') saving("${output}compliers_west.csv") title(`var') format(%5.4f)  append
}
	

* Non-Western-origin immigrants
* -----------------------------

* Main profile variables
foreach var in $desc_profilevars3  $desc_profilevars1  {
	
	ivdesc `var' veteran draft_risk if sample_main3 == 1, fmt(%5.4f)
	matrix O`var' = r(ivdesc)

}


* Proportions of compliers, AT, and NT
matrix define R = J(4,2,0)
matrix rownames R = "Whole Sample" "Complier" "Never-taker" "Always-taker"
matrix colnames R = "Proportion" "Boot.-SE"
forvalues r = 1 / 4 {
	matrix R[`r',1] = Oprofileage[`r',3] 
	matrix R[`r',2] = Oprofileage[`r',4] 
}

* View the matrices
matrix list R


* Tables for graphing later

mat2txt, matrix(R) saving("${output}compliers_nonwest.csv") title("Proportion") format(%5.4f)  append

foreach var in $desc_profilevars1 $desc_profilevars3 {
	mat2txt, matrix(O`var') saving("${output}compliers_nonwest.csv") title(`var') format(%5.4f)  append
}
	



	
* ---------------------------------------------------------------------------- *

* ----------------------------------------- *
* CHECKING FOR EXCESS MORTALITY: TABLE A8.4 *
* ----------------------------------------- *


* matrix to store the results
mata: MOR = J(3, 4, "")


* expected percentages of draft-eligible men in each cohort:
* (calculated as the average of each year's APN divided by # of days in that year)
* APN data are external
local p1949 = 0.417


* proportions
local row = 1

	mata: MOR[`row',1] = "1949--52"
	
	local row = `row' + 3



* full sample
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2
	
	su draft_risk if birth_year >= 1949 & birth_year <= 1952
	prtesti `r(N)' `r(mean)' 0.417
	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',2] = "`mu'"
	mata: MOR[`prow',2] = "(`pval')"
	mata: MOR[`nrow',2] = "N = `obs'"
	
	local row = `row' + 3
		



* western sample
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2

	su draft_risk if birth_year >= 1949 & birth_year <= 1952 & origin == 1
	prtesti `r(N)' `r(mean)' 0.417	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',3] = "`mu'"
	mata: MOR[`prow',3] = "(`pval')"
	mata: MOR[`nrow',3] = "N = `obs'"
	
	local row = `row' + 3
		


* non-western sample
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2

	su draft_risk if birth_year >= 1949 & birth_year <= 1952 & origin == 0
	prtesti `r(N)' `r(mean)' 0.417
	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',4] = "`mu'"
	mata: MOR[`prow',4] = "(`pval')"
	mata: MOR[`nrow',4] = "N = `obs'"
	
	local row = `row' + 3
		

* looking at the results
mata MOR

* output to latex
mmat2tex MOR using "${output}attrition.tex", replace ///
	colnames("Predicted" "Pooled sample" "Western-origin" "Non-western-origin") ///
	rownames("1949--52" "" "") 


	
* ---------------------------------------------------------------------------- *

* ------------------------------------ *
* ATTRITION BY NATIONALITY: TABLE A8.5 *
* ------------------------------------ *

* matrix to store the results
mata: MOR = J(3, 7, "")


* expected percentages of draft-eligible men in each cohort:
* (calculated as the average of each year's APN divided by # of days in that year)
* APN data are external
local p1949 = 0.417 


* proportions
local row = 1

	mata: MOR[`row',1] = "0.417"
	
	local row = `row' + 3


* Germans 
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2
	
	su draft_risk if birth_year >= 1949 & birth_year <= 1952 & bpl == 110
	prtesti `r(N)' `r(mean)' 0.417
	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',2] = "`mu'"
	mata: MOR[`prow',2] = "(`pval')"
	mata: MOR[`nrow',2] = "N = `obs'"
	
	local row = `row' + 3
		

* Italians
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2

	su draft_risk if birth_year >= 1949 & birth_year <= 1952 & bpl == [redacted]
	prtesti `r(N)' `r(mean)' 0.417	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',3] = "`mu'"
	mata: MOR[`prow',3] = "(`pval')"
	mata: MOR[`nrow',3] = "N = `obs'"
	
	local row = `row' + 3
	


* Mexicans
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2

	su draft_risk if birth_year >= 1949 & birth_year <= 1952 & bpl == [redacted]
	prtesti `r(N)' `r(mean)' 0.417	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',4] = "`mu'"
	mata: MOR[`prow',4] = "(`pval')"
	mata: MOR[`nrow',4] = "N = `obs'"
	
	local row = `row' + 3
	

* non-Mexicans
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2

	su draft_risk if birth_year >= 1949 & birth_year <= 1952 & bpl != [redacted]
	prtesti `r(N)' `r(mean)' 0.417	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',5] = "`mu'"
	mata: MOR[`prow',5] = "(`pval')"
	mata: MOR[`nrow',5] = "N = `obs'"
	
	local row = `row' + 3	

	
* Puerto Ricans
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2

	su draft_risk if birth_year >= 1949 & birth_year <= 1952 & bpl == [redacted]
	prtesti `r(N)' `r(mean)' 0.417	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',6] = "`mu'"
	mata: MOR[`prow',6] = "(`pval')"
	mata: MOR[`nrow',6] = "N = `obs'"
	
	local row = `row' + 3
	
	

* English-speakers
local row = 1

	local prow = `row' + 1
	local nrow = `row' + 2

	su draft_risk if birth_year >= 1949 & birth_year <= 1952 & engl_exclusive == 1
	prtesti `r(N)' `r(mean)' 0.417	
	local mu : display %5.4f `r(P)'
	local pval : display %5.4f `r(p)'
	local obs : display `r(N)'
	
	mata: MOR[`row',7] = "`mu'"
	mata: MOR[`prow',7] = "(`pval')"
	mata: MOR[`nrow',7] = "N = `obs'"
	
	local row = `row' + 3	
	
	
	
* looking at the results
mata MOR

* output to latex
mmat2tex MOR using "${output}attrition_nationality.tex", replace ///
	colnames("Predicted" "Germans" "Italians" "Mexicans" "Non-Mexicans" "Puerto Ricans" "From English-speaking country") ///
	rownames("1949--52" "" "") 


	


* ---------------------------------------------------------------------------- *

* ------------------------------------------------------------------------------------------ *
* EXCLUSION RESTRICTION ANALYSIS: CANADIANS AND MEXICANS: TABLE A10.6 SECOND & THIRD COLUMNS *	
* ------------------------------------------------------------------------------------------ *

* Canadians vs. Westerners
* ------------------------

xtset bpl

* set up matrix
cap mata drop D_CANADA
mata: D_CANADA = J(27, 2, "")


* loop over DVs
local row = 1
foreach var of varlist naturalized res_integrate_tract res_integrate_blkgrp spouse_notconatl spouse_native married college_some college_grad unemployed {
	
	// set up matrix
	local serow = `row' + 1
	local nrow = `row' + 2
	
	// Canadians
	ivregress 2sls `var' ${covars} (veteran = draft_risk) if sample_main1 == 1 & bpl == [redacted], vce(robust) 
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: D_CANADA[`row',1] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: D_CANADA[`row',1] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: D_CANADA[`row',1] = "`b'**"
	}
	if `p' < 0.001 {
		mata: D_CANADA[`row',1] = "`b'***"
	}
	mata: D_CANADA[`serow',1] = "(`se')"
	mata: D_CANADA[`nrow',1] = "N = `e(N)'"	
	
	
	// Non-Canadian Westerners
	xtivreg `var' ${covars} (veteran = draft_risk) if sample_main1 == 1 & origin == 1 & bpl != [redacted], vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: D_CANADA[`row',2] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: D_CANADA[`row',2] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: D_CANADA[`row',2] = "`b'**"
	}
	if `p' < 0.001 {
		mata: D_CANADA[`row',2] = "`b'***"
	}
	mata: D_CANADA[`serow',2] = "(`se')"
	mata: D_CANADA[`nrow',2] = "N = `e(N)'"	

	local row = `row' + 3
	
}


* looking at the results
mata D_CANADA


* output to latex
mmat2tex D_CANADA using "${output}dodgers_canadians.tex", replace ///
	rownames("Naturalized" "" "" "Residential integration (tract)" "" "" "Residential integration (block group)" "" "" "Non-co-national spouse" "" "" "Native-born spouse" "" ""  "Married" "" "" "Some college" "" "" "College graduate" "" "" "Unemployed" "" "") ///
	colnames("Canadians" "Non-Canadian Westerners") ///
	insertendrow(1 "\hline")


* Mexicans vs. Non-Westerners
* ------------------------

xtset bpl

* set up matrix
cap mata drop D_MEXICO
mata: D_MEXICO = J(36, 2, "")


* loop over DVs
local row = 1
foreach var of varlist naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability engl_ability_pooled spouse_notconatl spouse_native married college_some college_grad unemployed {
	
	// set up matrix
	local serow = `row' + 1
	local nrow = `row' + 2

	
	// Mexicans
	ivregress 2sls `var' ${covars} (veteran = draft_risk) if sample_main1 == 1 & bpl == [redacted], vce(robust) 
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
		local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: D_MEXICO[`row',1] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: D_MEXICO[`row',1] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: D_MEXICO[`row',1] = "`b'**"
	}
	if `p' < 0.001 {
		mata: D_MEXICO[`row',1] = "`b'***"
	}
	mata: D_MEXICO[`serow',1] = "(`se')"
	mata: D_MEXICO[`nrow',1] = "N = `e(N)'"	

	
	// Non-Mexican non-Westerners
	xtivreg `var' ${covars} (veteran = draft_risk) if sample_main1 == 1 & origin == 0 & bpl != [redacted], vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: D_MEXICO[`row',2] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: D_MEXICO[`row',2] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: D_MEXICO[`row',2] = "`b'**"
	}
	if `p' < 0.001 {
		mata: D_MEXICO[`row',2] = "`b'***"
	}
	mata: D_MEXICO[`serow',2] = "(`se')"
	mata: D_MEXICO[`nrow',2] = "N = `e(N)'"	

	local row = `row' + 3
	
}


* looking at the results
mata D_MEXICO


* output to latex
mmat2tex D_MEXICO using "${output}dodgers_mexicans.tex", replace ///
	rownames("Naturalized" "" "" "Residential integration (tract)" "" "" "Residential integration (block group)" "" "" "Only English" "" "" "English ability" "" "" "English ability (pooled)" "" "" "Non-co-national spouse" "" "" "Native-born spouse" "" ""  "Married" "" "" "Some college" "" "" "College graduate" "" "" "Unemployed" "" "") ///
	colnames("Mexicans" "Non-Mexican non-Westerners") ///
	insertendrow(1 "\hline")
	
* ---------------------------------------------------------------------------- *

* ------------------------------------------------------- *
* APPENDIX: TERRITORY CITIZENS: TABLE A10.6 (LAST COLUMN) *
* ------------------------------------------------------- *

xtset bpl

* set up matrix
cap mata drop TERR
mata: TERR = J(33, 2, "")


* loop over DVs
local row = 1
foreach var of varlist res_integrate_tract res_integrate_blkgrp only_engl engl_ability engl_ability_pooled spouse_notconatl spouse_native  married college_some college_grad unemployed {
	
	// set up matrix
	local serow = `row' + 1
	local nrow = `row' + 2
	
	// Territory citizens
	ivregress 2sls `var' ${covars} (veteran = draft_risk) if sample_main1 == 1 & terr_cits == 1, vce(robust) 
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: TERR[`row',1] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: TERR[`row',1] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: TERR[`row',1] = "`b'**"
	}
	if `p' < 0.001 {
		mata: TERR[`row',1] = "`b'***"
	}
	mata: TERR[`serow',1] = "(`se')"
	mata: TERR[`nrow',1] = "N = `e(N)'"	


	// Everyone else
	xtivreg `var' ${covars} (veteran = draft_risk) if sample_main1 == 1  & terr_cits == 0, vce(robust) fe
	local b : display %5.4f _b[veteran]
	local se : display %5.4f _se[veteran]
	local p = r(table)[4,1]
	if `p' >= 0.05 {
		mata: TERR[`row',2] = "`b'"
	}
	if `p' >= 0.01 & `p' < 0.05 {
		mata: TERR[`row',2] = "`b'*"
	}
	if `p' >= 0.001 & `p' < 0.01 {
		mata: TERR[`row',2] = "`b'**"
	}
	if `p' < 0.001 {
		mata: TERR[`row',2] = "`b'***"
	}
	mata: TERR[`serow',2] = "(`se')"
	mata: TERR[`nrow',2] = "N = `e(N)'"	

	local row = `row' + 3
	
}


* looking at the results
mata TERR


* output to latex
mmat2tex TERR using "${output}territory.tex", replace ///
	rownames("Residential integration (tract)" "" "" "Residential integration (block group)" "" "" "Only English" "" "" "English ability" "" "" "English ability (pooled)" "" "" "Non-co-national spouse" "" "" "Native-born spouse" "" ""  "Married" "" "" "Some college" "" "" "College graduate" "" "" "Unemployed" "" "") ///
	colnames("Born in U.S. territories" "Not born in U.S. territories") ///
	insertendrow(1 "\hline")
	




* ---------------------------------------------------------------------------- *

* ------------------------------------------------------------- *
* EXCLUSION RESTRICTION ANALYSIS: COHORTS ANALYSIS: TABLE A11.7 *
* ------------------------------------------------------------- *	


xtset bpl


* All immigrants: Table A11.7
* ---------------------------

* set up matrix
cap mata drop COHORTSPOOL
mata: COHORTSPOOL = J(36, 5, "")


* loop over DVs
local row = 1
foreach var of varlist naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability  engl_ability_pooled spouse_notconatl spouse_native  married college_some college_grad unemployed {
	
	// set up matrix
	local serow = `row' + 1
	local nrow = `row' + 2
	
	
	// loop over birth cohorts
	forvalues column = 1 / 5 {
	
		local byear = `column' + 1948
		
		xtivreg `var' ${covars} (veteran = draft_risk) if birth_year == `byear', vce(robust) fe
		local b : display %5.4f _b[veteran]
		local se : display %5.4f _se[veteran]
		local p = r(table)[4,1]
		if `p' >= 0.05 {
			mata: COHORTSPOOL[`row',`column'] = "`b'"
		}
		if `p' >= 0.01 & `p' < 0.05 {
			mata: COHORTSPOOL[`row',`column'] = "`b'*"
		}
		if `p' >= 0.001 & `p' < 0.01 {
			mata: COHORTSPOOL[`row',`column'] = "`b'**"
		}
		if `p' < 0.001 {
			mata: COHORTSPOOL[`row',`column'] = "`b'***"
		}
		mata: COHORTSPOOL[`serow',`column'] = "(`se')"
		mata: COHORTSPOOL[`nrow',`column'] = "N = `e(N)'"	


	
	
	}
	
	local row = `row' + 3
	
	}	
	
	

* looking at the results
mata COHORTSPOOL


* output to latex
mmat2tex COHORTSPOOL using "${output}cohorts_pool.tex", replace ///
	rownames("Naturalized" "" "" "Residential integration (tract)" "" "" "Residential integration (block group)" "" "" "Only English" "" "" "English ability" "" "" "English ability (pooled)" "" ""  "Non-co-national spouse" "" "" "Native-born spouse" "" ""  "Married" "" "" "Some college" "" "" "College graduate" "" "" "Unemployed" "" "" ) ///
	colnames("1949" "1950" "1951" "1952" "1953") ///
	insertendrow(1 "\hline")

	

* Western-origin immigrants
* -------------------------

* set up matrix
cap mata drop COHORTSWEST
mata: COHORTSWEST = J(36, 5, "")


* loop over DVs
local row = 1
foreach var of varlist naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability engl_ability_pooled spouse_notconatl spouse_native  married college_some college_grad unemployed {
	
	local serow = `row' + 1
	local nrow = `row' + 2
	
	* loop over birth cohorts
	forvalues column = 1 / 5 {
	
		local byear = `column' + 1948
		
		xtivreg `var' ${covars} (veteran = draft_risk) if birth_year == `byear' & origin == 1, vce(robust) fe
		local b : display %5.4f _b[veteran]
		local se : display %5.4f _se[veteran]
		local p = r(table)[4,1]
		if `p' >= 0.05 {
			mata: COHORTSWEST[`row',`column'] = "`b'"
		}
		if `p' >= 0.01 & `p' < 0.05 {
			mata: COHORTSWEST[`row',`column'] = "`b'*"
		}
		if `p' >= 0.001 & `p' < 0.01 {
			mata: COHORTSWEST[`row',`column'] = "`b'**"
		}
		if `p' < 0.001 {
			mata: COHORTSWEST[`row',`column'] = "`b'***"
		}
		mata: COHORTSWEST[`serow',`column'] = "(`se')"	
		mata: COHORTSWEST[`nrow',`column'] = "N = `e(N)'"						
	}
	
	local row = `row' + 3
	
}		

* looking at the results
mata COHORTSWEST


* output to latex
mmat2tex COHORTSWEST using "${output}cohorts_west.tex", replace ///
	rownames("Naturalized" "" "" "Residential integration (tract)" "" "" "Residential integration (block group)" "" "" "Only English" "" "" "English ability" "" "" "English ability (pooled)" "" ""  "Non-co-national spouse" "" "" "Native-born spouse" "" "" "Married" "" "" "Some college" "" "" "College graduate" "" "" "Unemployed" "" "") ///
	colnames("1949" "1950" "1951" "1952" "1953") ///
	insertendrow(1 "\hline")
	
	

* Non-western-origin immigrants
* -----------------------------

* set up matrix
cap mata drop COHORTSNONWEST
mata: COHORTSNONWEST = J(36, 5, "")


* loop over DVs
local row = 1
foreach var of varlist naturalized res_integrate_tract res_integrate_blkgrp only_engl engl_ability  engl_ability_pooled spouse_notconatl spouse_native  married college_some college_grad unemployed {
	
	local serow = `row' + 1
	local nrow = `row' + 2
	
	* loop over birth cohorts
	forvalues column = 1 / 5 {
	
		local byear = `column' + 1948

		xtivreg `var' ${covars} (veteran = draft_risk) if birth_year == `byear' & origin == 0, vce(robust) fe
		local b : display %5.4f _b[veteran]
		local se : display %5.4f _se[veteran]
		local p = r(table)[4,1]
		if `p' >= 0.05 {
			mata: COHORTSNONWEST[`row',`column'] = "`b'"
		}
		if `p' >= 0.01 & `p' < 0.05 {
			mata: COHORTSNONWEST[`row',`column'] = "`b'*"
		}
		if `p' >= 0.001 & `p' < 0.01 {
			mata: COHORTSNONWEST[`row',`column'] = "`b'**"
		}
		if `p' < 0.001 {
			mata: COHORTSNONWEST[`row',`column'] = "`b'***"
		}
		mata: COHORTSNONWEST[`serow',`column'] = "(`se')"
		mata: COHORTSNONWEST[`nrow',`column'] = "N = `e(N)'"
		
	}
	
	local row = `row' + 3
	
}			

* looking at the results
mata COHORTSNONWEST

* output to latex
mmat2tex COHORTSNONWEST using "${output}cohorts_nonwest.tex", replace ///
	rownames("Naturalized" "" "" "Residential integration (tract)" "" "" "Residential integration (block group)" "" "" "Only English" "" "" "English ability" "" "" "English ability (pooled)" "" "" "Non-co-national spouse" "" "" "Native-born spouse" "" "" "Married" "" "" "Some college" "" "" "College graduate" "" "" "Unemployed" "" "") ///
	colnames("1949" "1950" "1951" "1952" "1953") ///
	insertendrow(1 "\hline")
	



* ---------------------------------------------------------------------------- *
